package com.hontech.bread.api

import android.annotation.SuppressLint
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale


@Serializable
data class ErrInfo(

    @SerialName("err_code")
    val errCode: Int,

    @SerialName("err_msg")
    val errMsg: String
) {

    override fun toString(): String {
        return "$errCode => $errMsg"
    }
}


@Serializable
data class Firm(
    val id: Long,
    val name: String,

    @SerialName("create_timestamp")
    val createTimestamp: Long,

    val size: Long,

    val description: String,

    val version: String
) {


    fun dateFormat(): String {
        val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
        val date = Date(createTimestamp * 1000)
        return sdf.format(date)
    }

    @SuppressLint("DefaultLocale")
    fun sizeFormat(): String {
        if (size < 1024) {
            return "${size}Byte"
        } else if (size < 1024 * 1024) {
            return String.format("%.2fKB", size / 1024.0)
        } else if (size < 1024 * 1024 * 1024) {
            return String.format("%.2fMB", size / 1024.0 / 1024.0)
        }
        return "${size}Byte"
    }
}

@Serializable
class DeviceLoginReq(
    @SerialName("mac_addr")
    val macAddr: String,

    val version: String
)


class PushReq(
    val cmd: String,
    val type: Int,
    val seq: Int,
    val body: ByteArray,
)

const val EC_OK = 0
const val EC_FAIL = 1























